var api = require('../../utils/api.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    radio: '1',
    exchange_note:'',
    isDisabled:false
  },
  onChange(event) {
    this.setData({
      radio: event.detail
    });
  },

  //退货退款
  exchangeOrder(){
    
    if (this.data.radio==0){
      return wx.showToast({
        title: '请选择类型',
        icon:''
      })
    }
    if (this.data.exchange_note == '') {
      return wx.showToast({
        title: '请填写理由',
        icon: ''
      })
    }
   let params={
      token: wx.getStorageSync('token'),
      id:this.data.b_id,
     exchange_type: this.data.radio,
     exchange_note: this.data.exchange_note
    }
    api.fetchApi('/Order/exchange_order', params).then(res=>{
      wx.showToast({
        title: '申请成功'
      })
      setTimeout(()=>{
        wx.navigateBack({
          
        })
      },800)
    })
  },

  //备注
  bindTextAreaBlur(e){
    console.log(e.detail.value)
    this.setData({
      exchange_note: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let b_id=options.bid;
    let status = options.status || '';
    let radio = status=='1'?'3':'1'
    this.setData({
      b_id,
      status,
      // radio
    })
    wx.request({
      url: app.globalData.host + '/Order/exchange_order?id=' + b_id + '&token=' + wx.getStorageSync('token'),
      method:'get',
      success:res=>{
        console.log(res)
        this.setData({
          isDisabled: res.data.data.exchange_type > 0 ? true : false,
          exchange_note: res.data.data.exchange_note,
          radio: this.data.isDisabled ? res.data.data.exchange_type + '' : radio
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})